package com.tbycoder.tby.controller;


import com.tbycoder.tby.entity.Request.LoginRequest;
import com.tbycoder.tby.entity.Request.ModifyRequest;
import com.tbycoder.tby.entity.Vo.LoginVo;
import com.tbycoder.tby.excption.BizException;
import com.tbycoder.tby.service.IIposLoginService;
import com.tbycoder.tby.utils.ApiResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tby
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/tby/ipos-login")
@CrossOrigin
public class IposLoginController {

    @Autowired
    IIposLoginService iIposLoginService;

    @PostMapping(value = "/login")
    @ApiOperation(value = "登录")
    public ApiResponse login(
            @RequestBody LoginRequest loginRequest
            ){
        LoginVo loginVo = null;
        try {
            loginVo = iIposLoginService.login(loginRequest);
        }catch (BizException e){
            return ApiResponse.error(e.getData());
        }
        return ApiResponse.success(loginVo);
    }

    @PostMapping(value = "/modify")
    @ApiOperation(value = "修改密码")
    public ApiResponse modify(
            @RequestBody ModifyRequest modifyRequest
            ){
        try {
            boolean success = iIposLoginService.modifyRequest(modifyRequest);
        }catch (BizException e){
            return ApiResponse.error(e.getData());
        }
        return ApiResponse.success();
    }



}
